<div class="centercontent">
	<div class="contenttitle2">
        <h3>Edit role</h3>
    </div>

    <form class="stdform" action="#" method="post">
    	<p>
        	<label>Role name</label>
            <span class="field">
            	<input type="text" name="role_name" class="smallinput" value="<?php echo $this->currentRole['role']; ?>" />
            </span>            
        </p>
        <p>
	    	<label>Role departments</label>
	        <span id="role_departments" class="dualselect">
	        	<select name="departments_first" multiple="multiple" size="10">	        		
	                <?php foreach ($this->departments as $department): ?>
	                	<option value="<?php echo $department['id'] ?>">
	                		<?php echo $department['name']; ?>
	                	</option>
	                <?php endforeach; ?>
	            </select>
	            <span class="ds_arrow">
	            	<span class="arrow ds_prev">&laquo;</span>
	                <span class="arrow ds_next">&raquo;</span>
	            </span>
	            <select name="departments_second" multiple="multiple" size="10">
	            	<?php foreach ($this->roleDepartments as $roleDepartment): ?>
	                	<option value="<?php echo $roleDepartment['id'] ?>">
	                		<?php echo $roleDepartment['name']; ?>
	                	</option>
	                <?php endforeach; ?>
	            </select>
	        </span>
	    </p>
    	<p>
	    	<label>Role resources</label>
	        <span id="resources" class="dualselect">
	        	<select name="resources_first" multiple="multiple" size="10">
	        		<?php foreach ($this->resources as $resource): ?>
	                	<option value="<?php echo $resource['id']; ?>">
	                		<?php echo $resource['resource']; ?>
	                		(<?php echo $resource['parent_resource']; ?>)
	                	</option>
	            	<?php endforeach; ?>
	            </select>
	            <span class="ds_arrow">
	            	<span class="arrow ds_prev">&laquo;</span>
	                <span class="arrow ds_next">&raquo;</span>
	            </span>
	            <select name="resources_second" multiple="multiple" size="10">
	            	<?php foreach ($this->roleResources as $roleResource): ?>
	                	<option value="<?php echo $roleResource['id']; ?>">
	                		<?php echo $roleResource['resource']; ?>
	                		(<?php echo $roleResource['parent_resource']; ?>)
	                	</option>
	            	<?php endforeach; ?>
	            </select>
	        </span>
	    </p>
	    <p>
	    	<label>Role types</label>
	        <span id="role_types" class="dualselect">
	        	<select name="types_first" multiple="multiple" size="10">
	        		<?php foreach ($this->categoryTypes as $type): ?>
	                	<option value="<?php echo $type['id']; ?>">
	                		<?php echo $type['type']; ?>
	                	</option>
	            	<?php endforeach; ?>
	            </select>
	            <span class="ds_arrow">
	            	<span class="arrow ds_prev">&laquo;</span>
	                <span class="arrow ds_next">&raquo;</span>
	            </span>
	            <select name="types_second" multiple="multiple" size="10">
	            	<?php foreach ($this->roleCategoryTypes as $roleType): ?>
	                	<option value="<?php echo $roleType['id']; ?>">
	                		<?php echo $roleType['type']; ?>
	                	</option>
	            	<?php endforeach; ?>
	            </select>
	        </span>
	    </p>
	    <p>
	    	<label>Кафедры</label>
	        <span class="field">
	        <select name="departments" id="departments">
	        	<option value="0" alt="ololo">Без кафедры</option>
                <?php foreach ($this->allDepartments as $department): ?>
                	<option value="<?php echo $department['id'] ?>">
                		<?php echo $department['name']; ?>
                	</option>
                <?php endforeach; ?>	            
	        </select>
	        </span>
	    </p>	    
	    <p>
	    	<label>Role categories</label>
	        <span id="role_categories" class="dualselect">
	        	<select name="categories_first" multiple="multiple" size="10">	        		
	            </select>
	            <span class="ds_arrow">
	            	<span class="arrow ds_prev">&laquo;</span>
	                <span class="arrow ds_next">&raquo;</span>
	            </span>
	            <select name="categories_second" multiple="multiple" size="10">
	            	<?php foreach ($this->roleCategories as $roleCategory): ?>
                	<option value="<?php echo $roleCategory['id'] ?>">
                		<?php echo $roleCategory['category_name']; ?>
                	</option>
                <?php endforeach; ?>
	            </select>
	        </span>
	    </p>	    
	    <p class="stdformbutton">
	    	<a class="stdbtn btn_lime" href="#!" id="save">Save</a>
	    </p>
	    <p>
	    	<div id="response" style="color: red;">	    		
	    	</div>
	    </p>
    </form>    
</div>
<div id="role_id"><?php echo $this->currentRole['id']; ?></div>

<script type="text/javascript" src="/back/js/my/roles.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var departmentId = $('#departments option:selected').val();
		getDeptCategories(departmentId);
		$('#save').live('click', function() {
			var data = getFormData();
			var roleId = $('#role_id').text();
			$.post(
				'/admin/ajax/edit-role', 
				{
					data: data,
					role_id: roleId
				}, 
				function(response) {				
					response = JSON.parse(response);
					$('#response').html(response.message);
			    }
			)
		})
	})
</script>